package vip.zcn.webmanagement.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.zcn.webmanagement.mapper.DeptMapper;
import vip.zcn.webmanagement.pojo.Dept;
import vip.zcn.webmanagement.service.DeptService;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class DeptServiceImpl implements DeptService {


    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        // 调用mapper查询所有部门
        return deptMapper.list();
    }

    @Override
    public void delete(Integer id) {
        // 调用mapper删除部门
        deptMapper.delete(id);
        log.info("删除部门成功，id为{}", id);
    }

    @Override
    public void add(Dept dept) {
        // 设置创建时间和更新时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        // 调用mapper添加部门
        deptMapper.insert(dept);
        log.info("添加部门成功，id为{}", dept.getId());
    }

    @Override
    public Dept get(Integer id) {
        // 调用mapper查询部门
        Dept dept = deptMapper.selectDeptById(id);
        return dept;
    }

    @Override
    public void edit(Dept dept) {
        // 设置更新时间
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
        log.info("修改部门成功，id为{}", dept.getId());
    }
}
